package com.ygqh.baby.controller.kids;

import com.alibaba.fastjson.JSON;
import com.ygqh.baby.ao.ResponseEntity;
import com.ygqh.baby.po.AdminInvoice;
import com.ygqh.baby.service.AdminInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Author: sunshuo
 * @Date: 2019/9/25/025 17:36
 * @Version: 1.0
 */
@RequestMapping("admin/kids")
@Controller
public class KidsInvoiceController extends BaseKidsController {

    @Autowired
    private AdminInvoiceService adminInvoiceService;

    @RequestMapping(value = "saveInvoice", method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity saveInvoice(@RequestBody AdminInvoice invoice) {
        logger.info("接口推送发票，invoice={}", JSON.toJSONString(invoice));
        invoice.setUpdateBy("接口推送发票");
        invoice.setUpdateTime(new Date());
        if (invoice.getId() == null) {
            invoice.setCreateTime(invoice.getUpdateTime());
            invoice.setCreateBy(invoice.getUpdateBy());
        }
        return ResponseEntity.success(adminInvoiceService.saveOrUpdate(invoice));
    }
}
